package com.road7.mina.withprotobuf;

import java.io.IOException;
import java.net.InetSocketAddress;

import org.apache.mina.core.service.IoAcceptor;
import org.apache.mina.core.session.IoSessionConfig;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;

import com.road7.mina.customCodec.ProtobufStrictCodecFactory;

/**
 * @Description :
 * @FileName: Server.java
 * @Author :WeiHui.Zhang
 * @Data : 2015年11月20日 下午5:37:06
 * @Version:V1.00
 */
public class Server {

	public static final int PORT = 9999;

	public static void main(String[] args) throws IOException {
		IoAcceptor acceptor = new NioSocketAcceptor(Runtime.getRuntime().availableProcessors() + 1);

		IoSessionConfig ioSessionConfig = acceptor.getSessionConfig();

		ioSessionConfig.setMaxReadBufferSize(1024 * 4);

		acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new ProtobufStrictCodecFactory()));
		acceptor.setHandler(new ServerHandler("服务器Handler"));// 指定业务逻辑处理器
		acceptor.setDefaultLocalAddress(new InetSocketAddress(PORT));
		acceptor.bind();

	}
}
